package com.itheima.controller;


import com.itheima.pojo.Brand;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
@ResponseBody
@Controller
@RequestMapping("/brand")
public class BrandController {


    // 查询ID

    /**
     * @param id
     * @return
     * @GetMapping("/{id}") 路径参数(" / { id } ")
     * @PathVariable 路径参数  跟类型参数
     */
    @GetMapping("/{id}")
    @ResponseBody
    public Brand findById(@PathVariable Integer id) {
        Brand brand = new Brand();
        brand.setId(id);
        brand.setBrandName("heimama");
        brand.setCompanyName("chuanzhizhizhi");
        return brand;
    }

    // 查询全部
    @GetMapping     // http://localhost:8081/brand
    @ResponseBody
    public List findAll() {
        ArrayList<Brand> brands = new ArrayList<Brand>();
        Brand brand = new Brand();
        brand.setId(1);
        brand.setBrandName("heima");
        brand.setCompanyName("chuanzhi");

        brands.add(brand);
        brands.add(brand);
        brands.add(brand);
        return brands;
    }

    // 添加

    @PostMapping    // http://localhost:8081/brand   post
    @ResponseBody
    public String save(Brand brand) {
        System.out.println(brand);
        return "ok~";
    }

    // 删除

    @DeleteMapping("/{id}")
    @ResponseBody
    public String delete(@PathVariable Integer id) {

        System.out.println(id);

        return "delete OK!";
    }

    // 修改
    @PutMapping
    @ResponseBody
    public String update(@RequestBody Brand brand) {

        System.out.println(brand);

        return "update OK!";
    }


}
